package com.example.vehicleservice.controller1;

import com.alibaba.fastjson.JSON;
import com.example.vehicleservice.bean1.SugarOne;
import com.example.vehicleservice.bean1.TripMetrics;
import com.example.vehicleservice.service1.NewCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/NewVehicle")
public class NewCarController1 {
    @Autowired
    private NewCarService newCarService;
    /*
     * 获取行程信息
     */
    @RequestMapping("/getTripMetrics")
    private String getTripMetrics(){
        List<TripMetrics> tripMetrics = newCarService.getTripMetrics();
        for (TripMetrics tripMetric : tripMetrics) {
            System.out.println(tripMetric.toString());
        }
        if (tripMetrics == null || tripMetrics.isEmpty()){
            return "[]";
        }
        ArrayList<SugarOne> name = new ArrayList<>();
        name.add(new SugarOne("车辆唯一标识", "vin"));
        name.add(new SugarOne("行驶里程(km)", "distance"));
        name.add(new SugarOne("行驶时长(毫秒)", "duration"));
        name.add(new SugarOne("平均速度(km/h)", "vgSpeed"));
        name.add(new SugarOne("最高速度(km/h)", "maxSpeed"));
        name.add(new SugarOne("是否超速", "speeding"));

        return "{\n" +
                "  \"status\": 0,\n" +
                "  \"hitSugarSelf\": true,\n" +
                "  \"msg\": \"\",\n" +
                "  \"data\": {\n" +
                "    \"columns\": " +
                JSON.toJSONString(name)
                + ",\n" +
                "    \"rows\": " +
                JSON.toJSONString(tripMetrics)
                + "\n" +
                "  }\n" +
                "}";
    }


}
